#pragma once

/* 
*	Purpose: To display a GUI panel on the screen with additional features.
*
*/

#include "Globals.hpp"
#include "GLPrimitives.h"
#include "Button.h"
#include "Timer.hpp"
#include "GenericKeys.h"


#include <vector>
#include <string>
using namespace std;

// A struct that stores useful information for "mini panels" inside the panel.
struct GUIPanel_struct
{
	int x, y, w, h;
	OGL_Color color;
};

struct GUIPanel_text_struct
{
	int x, y;
	string text;
	OGL_Color color;
	string font_name;
};

class GUIPanel
{
public:

	GUIPanel();
	~GUIPanel();
	
	// Set the GUI panel dimensions and location
	void SetDimensions(const Coords &coordinates, const Dimension &dimensions) {m_dimensions.w = dimensions.w; m_dimensions.h = dimensions.h;
																				m_coordinates.x = coordinates.x; m_coordinates.y = coordinates.y; }
	
	// Draw the panel on the screen
	void DrawOpaq();
	void DrawTrans();

	// Handle events like a mouse going over a button
	void HandleGraphicalEvents();

	// Fade in / out
	inline void FadeIn() {m_active = true; m_fadeInOut = true; m_fadeIncementLevel = abs(m_fadeIncementLevel); m_timer.Restart();}
	inline void FadeOut() {m_fadeInOut = true; m_fadeIncementLevel = (-1) * abs(m_fadeIncementLevel); m_timer.Restart();}
	inline void SetFadeIncementLevel(float val) {m_fadeIncementLevel = val;}

	// Get and set if the panel is active / not active
	inline bool GetActive() {return m_active;}
	inline void SetActive(bool cond) {m_active = cond;}
	
	// Checks to see if the mouse cursor is in the specified button's bounds
	bool GetBounds(int button); 
	void AddButton(const Coords& coordinates, const Dimension& dimensions, string buttonText, string imgID, string mouseover_imgID);

	// Returns whether the cursor is in the panel's bounds
	bool GetPanelBounds(const int& x, const int& y);  // x and y are in the screen's coordinate plane

	// Sets the display color of the panel
	void SetColor(const OGL_Color& color);
	void SetAlpha(const float& val) {m_color.a = val;}

	// Used to update the buttons / anything with a texture in the panel
	void Update();

	// Gets the panel's coordinates
	Coords GetCoords() {return m_coordinates;}
	Dimension GetDimensions() {return m_dimensions;}
	int GetBottomY() {return m_coordinates.y + m_dimensions.h;} // returns the bottom y pixel of the panel

	// Add additional panels / rectangles to the GUI panel
	void AddPanel(int x, int y, int w, int h, const OGL_Color& color);
	void AddText(int x, int y, const char* text, const OGL_Color& color, const char* font_name);
	void ClearText();

	// Is the alpha level high enough that textures outside of the panel should be drawn?
	bool DrawExternalTextures();

private:
	// The actual dimensions & coordinates of the panel
	Dimension m_dimensions;
	Coords m_coordinates;

	// Used to determine if the panel is active
	bool m_active;

	// What fade level is the panel?
	Timer m_timer;
	float m_fade;
	float m_fadeIncementLevel;
	bool m_fadeInOut;

	// The buttons used in the panel
	vector<Button> m_buttons;
	
	// The additional panels
	vector<GUIPanel_struct> m_panels;
	vector<GUIPanel_text_struct> m_texts;

	// The display color of the panel
	OGL_Color m_color;


};